import ResultMixin from '@/mixins/resultMixin'

export default {
  mixins: [ResultMixin],
  data() {
    return {
      listQuery: {
        pageNum: 1,
        pageSize: 20
      },
      total: 0,
      tableData: [],
      editInfo: {
        editType: '',
        editFlag: false,
        editMap: {
          create: '创建',
          update: '编辑',
          search: '查看',
        },
      },
      temp: {}
    }
  },
  methods: {
    handleSizeChange(val) {
      this.listQuery.pageSize = val
      this.loadList()
    },
    handleCurrentChange(val) {
      this.listQuery.pageNum = val
      this.loadList()
    },
    editHandle(row) {
      this.editInfo.editFlag = true
      this.temp = Object.assign({}, row)
      this.editInfo.editType = 'update'
    },
    createHandle(event, cbk = () => {
    }) {
      this.editInfo.editFlag = true
      this.temp = {}
      cbk()
      this.editInfo.editType = 'create'
    },
    searchHandle(row) {
      this.editInfo.editFlag = true
      this.temp = Object.assign({}, row)
      this.editInfo.editType = 'search'
    },
    doCreateBefore() {
      this.$refs.editForm.validate(() => {
        this.doCreate()
      })
    },
    doUpdateBefore() {
      this.$refs.editForm.validate(() => {
        this.doUpdate()
      })
    },
    saveCbk() {
      this.loadList()
      this.editInfo.editFlag = false
    }
  },
  mounted() {
    this.loadList()
  }
}
